package fe.pong.tennis.fisica;

import flash.display.Sprite;
import fe.pong.tennis.gameElements.GameElement;
import fe.pong.tennis.gameElements.Personaje;
import fe.pong.tennis.gameElements.Player;

class ManagerCollision {

	private var elementos : Array<Player>;

	public function new() {
		elementos = new Array<Player>();
	}

	public function addElement(s : Player) {
		elementos.push(s);
	}

	public function removeElement(s : Player) {
		elementos.remove(s);
	}

	public function getCollision(obj1:Personaje): Player {
		for (obj2 in elementos)
			if (collisions(obj1, obj2))
				return obj2;
		return null;
	}

	private static function collisions(a: Sprite, b: Sprite): Bool {
		return
			a.x < b.x + b.width &&
			b.x < a.x + a.width &&
			a.y < b.y + b.height &&
			b.y < a.y + a.height;
	}

}